package com.nit.lab.vote.service.basic.impl;

import com.nit.lab.vote.dto.utils.PagingDTO;
import com.nit.lab.vote.dto.utils.TableReqDTO;
import com.nit.lab.vote.dto.utils.TableRspDTO;
import com.nit.lab.vote.mapper.basic.SubjectMapper;
import com.nit.lab.vote.service.basic.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SubjectServiceImpl implements SubjectService {
    @Autowired(required = false)
    private SubjectMapper subjectMapper;

    @Override
    public TableRspDTO list4Table(TableReqDTO tableReqDTO) throws Exception {
        TableRspDTO tableRspDTO = new TableRspDTO();
        Long count = subjectMapper.count4Table(
                tableReqDTO.parseQueryParam("typeName")
        );
        PagingDTO pagingDTO = new PagingDTO(
                tableReqDTO.getPageNo(),
                tableReqDTO.getPageSize(),
                count,
                subjectMapper.list4Table(
                        tableReqDTO.parseQueryParam("typeName"),
                        tableReqDTO.getStart(),
                        tableReqDTO.getPageSize(),
                        tableReqDTO.getSortField(),
                        tableReqDTO.getSortOrder()));

        return new TableRspDTO(pagingDTO);
    }
}
